<template>
	<view>
		<bg-video></bg-video>
		<cu-custom bgColor="bg-blue" :isBack="true">
			<block class="text-white" slot="content">房间</block>
		</cu-custom>
		<view>
			<view class="padding-sm" v-for="(room,index) in rooms" :key="index">
				<view class="bg-white shadow radius">
					<room-item :path="'/pages/cdz/fj'" :room="room" :showE="true"></room-item>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data: function() {
			return {
				rooms: [],
				pageInfo: {
					current: 1,
					size: 16,
					total: 0
				},
				locamap: {},
				tp: {},
				func: {}
			}
		},
		computed: {
			currentPosition: function() {
				if (this.store.state.position) {
					return this.store.state.position;
				}
				return undefined;
			}
		},
		created: function(){
			this.constant.get("ROOMFUNC").then(data => {
				this.func = data.ROOMFUNC;
			});
			this.constant.get("ROOMTP").then(data => {
				this.tp = data.ROOMTP;
			});
		},
		onLoad: function() {
			
			this.search();
		},
		methods: {
			search: function() {
				this.rooms = [];
				this.pageInfo.current = 1;
				this.loadRooms();
			},
			loadMore: function() {
				this.pageInfo.current++;
				this.loadRooms();
			},
			loadRooms: function() {
				let param = {
					current: this.pageInfo.current,
					size: this.pageInfo.size,
					dzid: this.store.state.dz.dzid,
					flg: true
				};
				if (this.currentPosition) {
					param.jd = this.currentPosition.jd;
					param.wd = this.currentPosition.wd;
				}
				this.api("/room/page").send(param).then(data => {
					this.pageInfo.current = data.arooms.current;
					for (let index in data.arooms.records) {
						let record = data.arooms.records[index];
						record.sheng = this.location.localmap.cmap[record.pcode].criname;
						record.shi = this.location.localmap.cmap[record.scode].criname;
						record.qu = this.location.localmap.cmap[record.qcode].criname;
						record.tpname = this.tp[record.tp];
						record.funcname = this.func[record.func];
						if (record.distance) {
							record.distance = this.util.formatDistance(record.distance);
						}
						this.rooms.push(record);
					}
				});
				
			
			},
		}
	}
</script>

<style>
</style>